package huaweiod.third;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 篮球比赛
 * https://blog.csdn.net/qfc_128220/article/details/127710678
 */
public class B_BasketballGame {

    public static int ans = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] arr = Arrays.stream(in.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        dfs(0, 0, 0, arr, Arrays.stream(arr).sum());
        System.out.println(ans);
    }

    private static void dfs(int cur, int count, int power, int[] arr, int sum) {
        if(cur == arr.length) {
            return;
        }
        if (count == 5) {
            ans = Math.min(ans, Math.abs(sum - 2 * power));
            return;
        }
        dfs(cur + 1, count, power, arr, sum);
        dfs(cur + 1, count + 1, power + arr[cur], arr, sum);
    }
}
